package com.ischoolbar.programmer.util;

/**
 * @Author lin
 **/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbUtil {
    private String dbUrl = "jdbc:mysql://localhost:3306/db_student_manager_web?serverTimezone=Asia/Shanghai";
    private String dbUser = "root";
    private String dbPassword = "123456";
    private String jdbcName = "com.mysql.cj.jdbc.Driver";
    private Connection connection = null;

    public DbUtil() {
    }

    public Connection getConnection() {
        try {
            Class.forName(this.jdbcName);
            this.connection = DriverManager.getConnection(this.dbUrl, this.dbUser, this.dbPassword);
            System.out.println("数据库链接成功！");
        } catch (Exception var2) {
            System.out.println("数据库链接失败！");
            var2.printStackTrace();
        }
        return this.connection;
    }

    public void closeCon() {
        if (this.connection != null) {
            try {
                this.connection.close();
                System.out.println("数据库链接已关闭！");
            } catch (SQLException var2) {
                var2.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        DbUtil dbUtil = new DbUtil();
        dbUtil.getConnection();
    }
}
